package com.projektio.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public abstract class Filter 
{
	public abstract Image doFiltering(Image image);
	
	public static void main(String ... args)
	{
		BitmapImageIO bir = new BitmapImageIO();
		Image image;
		int[][] normal = {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}};
		int[][] blured = {{1, 0, 1}, {0, 1, 0}, {1, 0, 1}};
		int[][] roberts = {{0, 0, 0}, {0, 1, 0}, {0, 0, -1}};
		int[][] detect = {{-1,-1,-1}, {-1,8,-1}, {-1,-1,-1}};
		MatrixFilter filter = new MatrixFilter(detect, 1);
				
		try 
		{
			image = bir.readImage(new FileInputStream("E:/testImageBig.bmp"));
			
			image = image.getGrayScaleImage();
			int otsu =  image.getOtsuThreshold();
			System.out.println("Otsu: " + otsu);
			
			
			//bir.saveImage(new FileOutputStream("E:/histogram.bmp"), bir.histogramToImage(image.getHistogram(0)) );
			//bir.saveImage(new FileOutputStream("E:/outputGrayImage.bmp"), image.getGrayScaleImage());
			image = image.getBinaryImage(otsu);
			bir.saveImage(new FileOutputStream("E:/outputBWImage.bmp"), image);
			bir.saveImage(new FileOutputStream("E:/outputEdgeBWImage.bmp"), filter.doFiltering(image));
		}
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		}
		System.out.println("Image saved!");
	}
}
